<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="css/aui.css">
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>

    <title>充值申请</title>
</head>
<body>
<header>
    <a href="javascript:history.back(-1)" class="f1 head-back"></a>
    <div class="f8">充值申请</div>
    <div class="f1"></div>
</header>
<section class="bg-gray">
    <ul class="pad-3">
        <li class="bg-white border-radius-1 border-gray hidden flex mar-b-2">
            <p class="col-3 bg-gray-l border-r-gray pad-2 center">充值地址</p>
            <p id="copylink" class="f1 pad-1-2 ellipsis"></p>
            <span id="copy" class="pad-1-2 bg-blue border-radius-1 color-white mar-r-2" onclick="getcopy()">复制</span>
        </li>
        <li id="btype" class="bg-white border-radius-1 border-gray hidden flex mar-b-2">
            <p class="col-3 bg-gray-l border-r-gray pad-2 center">充值币种</p>
            <p id="btext" class="f1 pad-1-2" data-id="1">以太坊（ETH）</p>
            <span class="arrow3 mar-r-2"></span>
        </li>
        <li class="bg-white border-radius-1 border-gray hidden flex mar-b-2">
            <p class="col-3 bg-gray-l border-r-gray pad-2 center">充值数量</p>
            <input id="money_num" class="f1 pad-1-2" type="number">
        </li>
        <li class="bg-white border-radius-1 border-gray hidden flex flex-stretch">
            <p class="col-3 bg-gray-l border-r-gray pad-2 center">备注</p>
            <textarea id="remark" class="f1 pad-2 font25 line-h-2"  rows="2" placeholder="必须输入自己的会员ID编号 + 自己的付款im钱包（交易所）地址！"></textarea>
        </li>

        <li id="tijiao" class="bg-blue pad-2-3 border-radius-1 color-white center mar-t-5">提交充值申请</li>
    </ul>
</section>

<!--mask-->
<div class="mask none"></div>
<div id="typebox" class="mask-box bg-white border-radius-1 hidden none">
    <p class="bg-blue pad-2 right"><span class="close"> </span></p>
    <ul id="typelist">
        <li class="flex pad-2-3 border-b-gray" data-id="1">
            <p class="f1">以太坊（ETH）</p>
            <span class="radio active"></span>
        </li>
        <li class="flex pad-2-3 border-b-gray" data-id="2">
            <p class="f1">以太经典（ETC）</p>
            <span class="radio"></span>
        </li>
    </ul>
</div>

<div id="notice" class="mask-box bg-white border-radius-1 hidden none">
    <p class="bg-blue pad-2 right">
        <span class="fl color-white">提示信息</span>
        <span class="close"> </span>
    </p>
    <div class="pad-3">
        <div class="pad-3 bg-gray-l flex">
            <span class="radio active mar-r-2"></span>
            复制成功
        </div>
    </div>

</div>

<script type="text/javascript" src="js/init.js"></script>
<script src="js/foot.js"></script>
<script>
    // 选择币种
    $("#btype").click(function () {
        $(".mask").show();
        $("#typebox").show();
    });
    $("#typelist li").click(function () {
        $("#typelist li .radio").removeClass('active');
        $(this).children('.radio').addClass('active');
        // 给币种赋值
        var text = $(this).children('p').text();
        $("#btext").text(text).attr('data-id',$(this).attr('data-id'));
        $(this).attr('data-id') == 1?$("#copylink").text(wallet_add.eth?wallet_add.eth:'暂无'):$(this).attr('data-id') == 2?$("#copylink").text(wallet_add.etc?wallet_add.etc:'暂无'):'';

        $(".mask").hide();
        $(".mask-box").hide();
    });
    
    // 关闭弹窗
    $(".close").click(function () {
        $(".mask").hide();
        $(".mask-box").hide();
    });

    var data;
    var wallet_add = {};
    // 获取充值地址
    new AjaxRequest({
        type: 'post',
        data: data,
        dataType: 'json',
        url: hostUrl + 'index/Recharge/getrechargeadd',
        callback: res => {
            if(res.status == 1){
                wallet_add.etc = res.data.ETC || '';
                wallet_add.eth = res.data.ETH || '';
                if($("#btext").attr('data-id') == 1){
                    $("#copylink").text(res.data.ETH?res.data.ETH:'暂无');
                }
                if($("#btext").attr('data-id') == 2){
                    $("#copylink").text(res.data.ETC?res.data.ETC:'暂无');
                }
            }


        }
    });

    $("#tijiao").click(function () {
        if(!($("#money_num").val() && $("#remark").val())){
            toast('请填写完整信息');
            return;
        }
        var v = $("#remark").val();
        var id_num = v.split('+')[0]?v.split('+')[0].trim():'';
        var jy_wallet_add = v.split('+')[1]?v.split('+')[1].trim():'';

        var data = {
            userid: localStorage.user_id,
            token: localStorage.token,
            recmoney: $("#money_num").val(),
            id_num: id_num,
            jy_wallet_add: jy_wallet_add,
            coin_type: $("#btext").attr('data-id'),
        };
        console.log(data);
        new AjaxRequest({
            type: 'post',
            data: data,
            dataType: 'json',
            url: hostUrl + 'index/Recharge/reccommit',
            isShowLoader: true,
            callback: res => {
                toast(res.msg);
                if(res.status == 1){
                    setTimeout(function () {
                        window.location.href = 'pay.html';
                    },2000)
                }

            }
        })
    })
</script>
</body>
</html>